﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QunYing.BLL;
using Maticsoft.Common;
using System.Collections;

namespace QunYing.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtUserName.Focus();
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            BLL.UserLoginInfo user = new BLL.UserLoginInfo();
            ArrayList loginUser = user.Login(txtUserName.Text.Trim(), txtUserPwd.Text.Trim());
            if (loginUser.Count > 0)
            {
                try
                {
                    if (Convert.ToDateTime(loginUser[3]) < DateTime.Now)
                    {
                        MessageBox.Show(UpdatePanel1, "帐户已到期!"); 
                        return;
                    }
                }
                catch (Exception)
                {

                    MessageBox.Show(UpdatePanel1, "帐户已到期!");
                    return;
                }

                if (loginUser[2].ToString() == "会员")
                {
                    user.UpdateTime(txtUserName.Text.Trim());
                    Session["userInfo"] = loginUser;
                    Response.Redirect("~/warn.aspx");
                }
                //else if (loginUser[2].ToString() == "经销商")
                //{
                //    user.UpdateTime(txtUserName.Text.Trim());
                //    Session["userInfo"] = loginUser;
                //    Response.Redirect("~/Dealer/Default.aspx");
                //}
                else
                {
                    MessageBox.Show(UpdatePanel1, "帐户未授权,请联系管理员!");
                }
            }
            else
            {
                MessageBox.Show(UpdatePanel1, "用户名或密码错误!");
                txtUserPwd.Focus();
            }
        }

        protected void btnForget_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ForgetPwd.aspx");
        }
    }
}
